﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A70属性
{
    public class Program
    {
        static void Main(string[] args)
        {
            Student1 s1 = new Student1("张三");

            Console.WriteLine(s1.GetName());
            s1.SetName("李四");


            Student s = new Student("张三",1990);
            Console.WriteLine(s.Name);
            s.Name = "李四";
            Console.WriteLine(s.BirthYear);
            Console.WriteLine(s.Age);
        }
    }

    //C#中的属性语法
    class Student
    {
       public int X { get; set; }
       
        private string name;
        public string Name 
        {
            get { return name; }//本质是一个get方法
            set { name = value; } //本质是一个Set方法,value是赋值时 = 右边的值
        }

        private int birthYear;//出生年
        public int BirthYear 
        {
            get { return birthYear; }
        }
        public int Age 
        {
            get { return DateTime.Now.Year - birthYear; }
        }

        //自动属性   自动指的是 在编译时自动在中间语言生成字段
        public string  Set { get; set; }

        //构造函数
        public Student(string name,int birthYear)
        {
            this.Name = name;
            this.birthYear = birthYear;
        }
    }



}
